package com.leyou.item.mapper;

import com.leyou.item.pojo.Brand;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.additional.idlist.SelectByIdListMapper;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface BrandMapper extends Mapper<Brand>, SelectByIdListMapper<Brand,Long> {


    /**
     * 注解方式表达sql语句
     * 可以用于单表
     *
     * @param cid
     * @param bid
     */
    @Insert("insert into tb_category_brand (category_id,brand_id) values(#{cid},#{bid})")
    void insertCategoryBrand(@Param("cid") Long cid, @Param("bid") Long bid);

    @Delete("delete from tb_category_brand where brand_id=#{id}")
    void deleteCategory(@Param("id") Long id);

    @Select("select tb.id,tb.name,tb.image,tb.letter from tb_brand tb inner join tb_category_brand cb on cb.brand_id=tb.id where cb.category_id=#{cid} ")
    List<Brand> queryBrandByCategory(@Param("cid") Long cid);
}
